package co.infinum.goldfinger.example;

import co.infinum.goldfinger.Goldfinger;
import co.infinum.goldfinger.RestartPredicates;
import co.infinum.goldfinger.util.LogUtils;
import co.infinum.goldfinger.rx.RxGoldfinger;
import ohos.biometrics.authentication.BiometricAuthentication;

/**
 * ex.
 *
 * @author zh
 * @since 2021-06-25
 */
public class RxSettingsAbility extends BaseSettingsAbility {
    private RxGoldfinger goldfinger;

    @Override
    protected void encryptFingerprintPin(String pin) {
        goldfinger.encrypt(RestartPredicates.defaultPredicate(), "fp_pin", pin).subscribe(result -> {
            handleGoldfingerResult(result);
        }, error -> {
            handleGoldfingerError(error);
        });
    }

    @Override
    protected void initGoldfinger() {
        this.goldfinger = new RxGoldfinger.Builder(this)
                .setAuthType(BiometricAuthentication.AuthType.AUTH_TYPE_BIOMETRIC_FACE_ONLY)
                .setSecureLevel(BiometricAuthentication.SecureLevel.SECURE_LEVEL_S2)
                .setLogger(new Goldfinger.Logger() {
                    @Override
                    public void log(String message) {
                    }

                    @Override
                    public void logException(Throwable throwable, String message) {
                    }

                })
                .logEnabled(true)
                .build();
    }
}
